import { Service } from 'egg';
import * as Archiver from 'archiver';

/**
 * Test Service
 */
export default class Test extends Service {

  /**
   * sayHi to you
   * @param name - your name
   */
  public async sayHi(name: string) {
    return `hi, ${name}`;
  }

  async test() {
    const arc = Archiver('zip', {
      zlib: { level: 9 }, // Sets the compression level.
    });

    arc.append('string cheese!', { name: 'file2.txt' });
    arc.append('test txt', { name: 'file.pem' });
    arc.finalize();

    this.ctx.set('Content-Disposition', 'attachment;filename=ssl.zip');
    this.ctx.type = 'application/zip, application/octet-stream';

    return arc;
  }
}
